﻿using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine.Assertions;
using XPython;

//transfer the events between csharp and python
public class SPF
{
    // TODO: 注意点, func被释放了后的处理逻辑，py obj生命周期的管理， PyObject是否要加一个字段表示有没有被释放
    public static string pyRegisterOut(int n, PyEnv.var[] argv)
    {
        // string eventname, PyEnv.PyObject func
        Assert.IsTrue(n == 3);

        string eventname = Marshal.PtrToStringAnsi(argv[1].str);
        PyEnv.Native_ReleaseMemory(out argv[1].str);

        PyEnv.PyObject func = new PyEnv.PyObject { id = argv[2].d };

        KBEngine.Event.registerOutPy(eventname, func);

        // 设置执行完后的返回值
        argv[0].type = PyEnv.var_type.INTEGER;
        argv[0].d = 0;
        return null;
    }

    public static void handleEventToPy(PyEnv.PyObject func, object[] arg)
    {

    }
}
